<?php
/**
 * Created by PhpStorm.
 * User: yf
 * Date: 2018/3/10
 * Time: 下午5:56
 */
namespace App\Server\PoolServer;

use EasySwoole\Config;
use EasySwoole\Core\Swoole\Coroutine\Client\Mysql;
// use EasySwoole\Core\Swoole\Coroutine\AbstractInterface\CoroutinePool;
use EasySwoole\Core\Component\Pool\AbstractInterface\Pool;

class MysqlPool2 extends Pool
{

//     function __construct($min, $max, $poolTableKey)
//     {
//         parent::__construct($min, $max, $poolTableKey);
//     }

    function getObj($timeOut = 0.1): ?Mysql
    {
        return parent::getObj($timeOut); // TODO: Change the autogenerated stub
    }

    protected function createObject()
    {
        // TODO: Implement createObject() method.
        $conf = Config::getInstance()->getConf('MYSQL');
        $db = new Mysql([
            'host' => $conf['HOST'],
            'username' => $conf['USER'],
            'password' => $conf['PASSWORD'],
            'db' => $conf['DB_NAME']
        ]);
        if (isset($conf['names'])) {
            $db->rawQuery('SET NAMES ' . $conf['names']);
        }
        return $db;
    }
}
